#!/bin/bash

. $ZMICRO_HOME/core/env

help() {
  echo "Usage:"
  echo "  zmicro fn <fn_name> <fn_args...>"
}

core() {
  if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
    help
    exit 0
  fi

  local fn=$1
  local args=${@:2}

  if [ -z "$fn" ]; then
    log::error "method is required"
    exit 1
  fi

  # @TODO
  # set +e

  type $fn >> /dev/null 2>&1
  if [ $? -eq 0 ]; then
    eval "$fn $args"
  else
    log::error "$fn method is not not found"
  fi

  # @TODO
  # set -e
}

run() {
  core $@
}

run $@
